package com.whj.ems.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.whj.ems.dao.CompanyDao;
import com.whj.ems.entity.Company;
@Repository("companyDao")
public class CompanyDaoImpl extends BaseDaoImpl<Company> implements CompanyDao {
	@Override
	public void save(Company company) throws Exception {
		super.save(company);
	}
	@Override
	public List<Company> get() throws Exception {
		return super.get();
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Company> getByfenye(int start,int number,String searchType,String urlPamer) throws Exception {
		DetachedCriteria criteria=DetachedCriteria.forClass(Company.class);
		if(!"gquanbu".equals(searchType)){
			if("gid".equals(searchType)){
				criteria.add(Restrictions.eq("gid", Integer.parseInt(urlPamer)));
			}else if("gname".equals(searchType)){
				criteria.add(Restrictions.like("gname", "%"+urlPamer+"%"));
			}else if("gemail".equals(searchType)){
				criteria.add(Restrictions.like("gemail", "%"+urlPamer+"%"));
			}else if("gQQ".equals(searchType)){
				if("".equals(urlPamer)){
					criteria.add(Restrictions.eq("gQQ", urlPamer));
				}else{
				criteria.add(Restrictions.like("gQQ", "%"+urlPamer+"%"));
				}
			}else if("gchuanzhen".equals(searchType)){
				if("".equals(urlPamer)){
					criteria.add(Restrictions.eq("gchuanzhen", urlPamer));
				}else{
				criteria.add(Restrictions.like("gchuanzhen", "%"+urlPamer+"%"));
				}
			}else if("gfuzeren".equals(searchType)){
				criteria.add(Restrictions.like("gfuzeren", "%"+urlPamer+"%"));
			}else if("gaddress".equals(searchType)){
				criteria.add(Restrictions.like("gaddress", "%"+urlPamer+"%"));
			}else if("gyuming".equals(searchType)){
				criteria.add(Restrictions.like("gyuming", "%"+urlPamer+"%"));
			}else if("gtelephone".equals(searchType)){
				criteria.add(Restrictions.like("gtelephone", "%"+urlPamer+"%"));
			}else if("gdate".equals(searchType)){
				String[] str=urlPamer.split(";");
				criteria.add(Restrictions.ge("gstartTime", str[0])).add(Restrictions.le("gendTime", str[1]));
			}
		}
		criteria.addOrder( Property.forName("id").desc());  
		return (List<Company>)this.getHibernateTemplate().findByCriteria(criteria, start, number);
	}

}
